package com.study.design.pattern.pattern.structural.proxy.dynamicproxy;

import java.lang.reflect.Proxy;

/**
 * @Author: gongsl
 * @Date: 2025-03-19 21:38
 */
public class DynamicProxyTest {
    public static void main(String[] args) {
        // 创建目标对象
        PaymentService paymentService = new PaymentServiceImpl();
        // 创建InvocationHandler实现对象
        PaymentServiceInvocationHandler handler = new PaymentServiceInvocationHandler(paymentService);
        // 创建代理对象
        PaymentService proxy = (PaymentService) Proxy.newProxyInstance(
                PaymentService.class.getClassLoader(),
                new Class[]{PaymentService.class},
                handler);
        // 通过代理对象调用方法
        proxy.pay("1000");
    }
}
